package com.xuanl.protagonist.service.robot;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuanl.protagonist.dto.ProPersonRobotDo;
import com.xuanl.protagonist.mapper.ProPersonRobotMapper;
import com.xuanl.protagonist.vo.ProPersonRobotVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service
@Slf4j
public class ProPersonRobotServiceImpl implements ProPersonRobotService {

    @Resource
    private ProPersonRobotMapper mapper;


    /**
     * 查询列表数据
     * @param proPersonRobotVo
     * @return
     */
    @Override
    public List<ProPersonRobotDo> getList(ProPersonRobotVo proPersonRobotVo) {
        List<ProPersonRobotDo> robotDos = mapper.selectList(buildWrapper(proPersonRobotVo));
        return robotDos;
    }

    public LambdaQueryWrapper<ProPersonRobotDo> buildWrapper(ProPersonRobotVo proPersonRobotVo){
        LambdaQueryWrapper<ProPersonRobotDo> wrapper = new LambdaQueryWrapper<>();

        if(Optional.ofNullable(proPersonRobotVo.getRobotName()).isPresent()){
            wrapper.like(ProPersonRobotDo::getRobotName, proPersonRobotVo.getRobotName());
        }
        return wrapper;
    }
}
